const {User} = require("../../moudles/accessdb/dao/userlogin");
const {handleRequest} = require("./userregister")

/*
处理登录 userinfo 是请求体
 */
async function handleLogin(userinfo) {
   return  handleRequest(userinfo);
}

/**
 * 验证用户登录
 * @returns {Promise<*>}
 */
async function handleValidUser(userinfo) {
    const user = await User.findOne({
            where: {userName: userinfo.account,
                    userPassword:userinfo.password},
            attributes: ['userId', 'userName', 'userPassword']
        }// 只返回 id、name 和 email 字段
    )
    return user;
}

module.exports = {handleLogin,handleValidUser}